package cn.edu.nwsuaf.examcenter.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.nwsuaf.examcenter.pojo.Cource;
import cn.edu.nwsuaf.examcenter.service.CourceService;

@Controller
@RequestMapping("/cource")
public class CourceController {
	@Resource(name="courceService")
	private CourceService courceService;
	
	/****
	 * 加载课程信息
	 * @param key
	 * @param p
	 * @param modelMap
	 * @return
	 */
	@RequestMapping(value="/loadCource")
	public String loadCource(@RequestParam(value="key",required=false)String key, 
			@RequestParam(value="p",required=false)String p,
			ModelMap modelMap){
			courceService.loadCource(modelMap);
		return "exam/cource-list";
	}
	
	/***
	 * 添加课程信息
	 * @param cource
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/addCource",method=RequestMethod.POST)
	public String addCource(@ModelAttribute Cource cource){
		return courceService.addCource(cource);
	}
	
	/****
	 * 单个删除课程信息
	 * @param courceNo
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/deleteCource/{courceNo}")
	public String deleteCource(@PathVariable(value="courceNo")String courceNo){
		return courceService.deleteCource(courceNo);
	}
	
	/****
	 * 批量删除课程信息
	 * @param array
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/deleteCourceList")
	public String deleteCourceList(@RequestParam(value="array")String array){
		return courceService.deleteCourceList(array);
	}
}
